﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using Batman.Cache;
using Batman.Cache.Attributes;
using Batman.Cms.Core.Const;
using Batman.Jianbei.Forum.Core.ChatRoom;
using Batman.Jianbei.Forum.Core.Datas;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace Batman.Jianbei.Forum.Services.ChatRoom
{
    public class MaskCacheService : ApplicationService, ICacheWorkable
    {
        public IRepository<Mask, string> MaskRepository { get; set; }

        /// <summary>
        /// 获取全部有效的匿名身份（含头像信息）
        /// </summary>
        /// <returns></returns>
        [Cacher(CacherType.Cache, Id = CacheNames.Masks)]
        public virtual List<Mask> GetMasks()
        {
            using (var ctx = new ChatRoomDbFactory().CreateDbContext(null))
            {
                return ctx.Mask.AsNoTracking().Where(t => !t.IsDeleted).Include(t => t.Avatar).ToList();
            }
        }
    }
}
